"""
http://spider.wangluozhe.com/challenge/3
"""
import time
import execjs
import requests

with open("js_3.js", "r")as f:
    q=f.read()


url = "http://spider.wangluozhe.com/challenge/api/3"
item = []
sum = 0
for i in range(1, 101):
    key = str(int(time.time() * 1000))
    message = "http://spider.wangluozhe.com/challenge/3"
    sign = execjs.compile(q)
    data = {
        "page": i,
        "count": 10,
        "_signature": sign.call("f",key,f"{message}|{key}")
    }
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36",
        "Cookie": "session=e6bfc695-c6ce-46f6-9ccd-a1f0d2835626.QAGPPsvuxBvBjqFAuBYxJYfF77M",
        "Host": "spider.wangluozhe.com",
        "Origin": "http://spider.wangluozhe.com",
        "Referer": "http://spider.wangluozhe.com/challenge/3"
    }
    res = requests.post(url=url, headers=headers,data=data)
    if res.status_code == 200:
        data_json = res.json().get("data")
        for i in data_json:
            value = i.get("value")
            print(f"当前数值为{value}")
            sum += value
    else:
        print("请求失败")
    time.sleep(0.75)
print(f"总数为{sum}")